//
//  UserDefaultsManager.swift
//  swiftProductTemplate
//
//  Created by 刘圣洁 on 2025/6/19.
//

import Foundation

// 用户偏好设置管理
class UserDefaultsManager {
    static let shared = UserDefaultsManager()
    private let userDefaults: UserDefaults
    
    private init(userDefaults: UserDefaults = .standard) {
        self.userDefaults = userDefaults
    }
    
    // 用户令牌
    var authToken: String? {
        get { return userDefaults.string(forKey: "authToken") }
        set { userDefaults.set(newValue, forKey: "authToken") }
    }
    
    // 用户ID
    var userId: String? {
        get { return userDefaults.string(forKey: "userId") }
        set { userDefaults.set(newValue, forKey: "userId") }
    }
    
    // 用户是否首次启动
    var isFirstLaunch: Bool {
        get { return userDefaults.bool(forKey: "isFirstLaunch") }
        set { userDefaults.set(newValue, forKey: "isFirstLaunch") }
    }
    
    // 清除所有数据
    func clearAllData() {
        let domain = Bundle.main.bundleIdentifier!
        userDefaults.removePersistentDomain(forName: domain)
        userDefaults.synchronize()
    }
}    
